package com.group.three.utils;

import lombok.Data;
import ws.schild.jave.MultimediaInfo;
import ws.schild.jave.MultimediaObject;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;


public class TimeUtils {
    public static String formatTime(Long ms){
        Integer ss = 1000;
        Integer mi = ss * 60;
        Integer hh = mi * 60;
        Integer dd = hh * 24;

        Long day = ms / dd;
        Long hour = (ms - day * dd) / hh;
        Long minute = (ms - day * dd - hour * hh) / mi;
        Long second = (ms - day * dd - hour * hh - minute * mi) / ss;
        Long milliSecond = ms - day * dd - hour * hh - minute * mi - second * ss;

        StringBuffer sb = new StringBuffer();
        if(day > 0) {
            sb.append(day+"天");
        }
        if(hour > 0) {
            sb.append(hour+"小时");
        }
        if(minute > 0) {
            sb.append(minute+"分");
        }
        if(second > 0) {
            sb.append(second+"秒");
        }
        return sb.toString();
}
    public static String getTimeByDate(Date date){
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    String formatTime = format.format(date);
    return formatTime;

}

    /**
     * 获取上传文件的长度
     * @param file
     * @return
     */
    public static Long getVideoTime(File file) {
        try {
            MultimediaObject instance = new MultimediaObject(file);
            MultimediaInfo result = instance.getInfo();
            // 毫秒 -> 秒 -> 分钟 -> 小时
            Long ls = result.getDuration();
            return ls;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0l;
    }

}
